home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
program
/
cuj0796.zip
/
COLNER.ZIP
/
HTML.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-08
|
2KB
|
87 lines
#include "html.h"
void
message( char* code, unsigned long line, char* file, char* date){
cout << (
Html("Error")
<< (Block("H1") << "Error!")
<< (Block("DL")
<< "\n<DT>CODE<DD>" << code
<< "\n<DT>LINE<DD>" << line
<< "\n<DT>FILE<DD>" << file
<< "\n<DT>DATE<DD>" << date
<< "\n"
)
);
}
//************************ Block messages *****************************
Block& Block :: operator
<< ( BlockOption& opt ){
if(blockOptionCount < 10) // Deep copy the option
option[blockOptionCount++] = new BlockOption(opt);
return *this;
}
Block ::
Block( Block& b): String(b), tag(b.tag){
for( blockOptionCount =0;
blockOptionCount < b.blockOptionCount;
blockOptionCount++
)option[blockOptionCount]
=new BlockOption(*b.option[b.blockOptionCount]);
}
Block ::
~Block(){
unsigned k =0;
while(k < blockOptionCount) delete option[k++];
}
Block& Block ::
filter(const char * text){
char *s =(char*)text, c;
while( (c =*s++) != 0 )switch(c){
case '&': *this << "&"; break;
case '<': *this << "<"; break;
default: *this << c;
}
return *this;
}
ostream& operator
<< ( ostream& out, Block& b){
out << "<" << b.tag;
unsigned k =0;
while(k < b.blockOptionCount)out << b.option[k++];
out << ">" ;
return out << (String&)b << "</" << b.tag << ">\n";
}
//************************ BlockOption *****************************
ostream& operator
<< ( ostream& out, BlockOption& b){
out << " ";
out << b.name;
out << "=\"";
out << (String&)b;
out << "\"";
return out;
}
//************************ Html messages *****************************
int Html::responseHeader =1;
ostream& operator
<<( ostream& out, Html& body){
Block htmlBlock("html");
if( body.title.notNull() || body.isIndex ){
Block head("head");
if(body.title.notNull()){
Block title("title");
title << body.title;
head << title;
}
if( body.isIndex )
head << "<isIndex>";
htmlBlock << head;
}
htmlBlock << (Block&)body;
if(Html::responseHeader)
out << "Content-type: text/html\n\n";
else
out << "Suppress: Content-type: text/html\n\n";
return out << htmlBlock << endl;
}